home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
room3d
/
mmain.bas
< prev
next >
Wrap
BASIC Source File
|
1999-05-18
|
50KB
|
1,142 lines
Attribute VB_Name = "mMain"
Option Explicit
'Almost all this module (except for buildworld and checkKeys)
'Was taken from Wolfgang Kienreich's Xdemo3D example
'Hardware support code was also fixed for me by Wolfgang.... many, many,
'thanx for that
'Variables for 3d objects in the scene
Global ObjectFrame(1 To 2) As IDirect3DRMFrame2 ' Frame to hold object
Public RMLight(1 To 2) As IDirect3DRMFrame
'Variables holding DDraw and D3DRM instances ...
Public G_oDDInstance As IDirectDraw ' Instance of DirectDraw interface
Public G_oD3DInstance As IDirect3DRM ' Instance of Direct3DRM interface
' Variables for primary D3DRM display system ...
Public RMDevice As IDirect3DRMDevice2 ' Device to use for Direct3DRM operations
Public RMViewport As IDirect3DRMViewPort ' Viewport for Direct3DRM to display results in
Public RMScene As IDirect3DRMFrame2 ' Top level frame that contains all other frames
Public RMCamera As IDirect3DRMFrame2 ' Frame to contain the camera; The viewport is created from this frame
Public RMDriver As tD3DDriver ' Driver for use with Direct3DRM
Public RMDriverExist As Boolean ' Flag holding presence of driver (equals driver enumeration success)
Public G_dCamPosLookup(359) As D3DVECTOR ' Lookup table of position values for camera
Public G_nCamPosCurrent As Integer ' Current position of camera according to lookup table
Global BufferDC As Long
' Variables for DirectDraw blit system ...
Public G_oDDPrimary As IDirectDrawSurface3 ' Primary DirectDraw surface that is displayed on the form
Public G_oDDBackbuffer As IDirectDrawSurface3 ' Backbuffer DirectDraw surface that is flipped onto the primary
Public G_dDDWindow(0) As tDDWindow ' Buffers holding windows for effects
' Various variables ...
Public G_nFrameCount As Long ' Global framecounter
Public G_nFrameAvg As Double ' Global average frames per second
' Various constants
Public Const PIFACTOR = 0.0174532
' Types for use with XDemo3D ...
' Driver type for enumeration of D3D driver
Public Type tD3DDriver
DESC As String ' Driver description
NAME As String ' Driver name
GUID As Byte ' Unique interface ID for accessing driver
GUID1 As Byte ' ...
GUID2 As Byte ' ...
GUID3 As Byte ' ...
GUID4 As Byte ' ...
GUID5 As Byte ' ...
GUID6 As Byte ' ...
GUID7 As Byte ' ...
GUID8 As Byte ' ...
GUID9 As Byte ' ...
GUID10 As Byte ' ...
GUID11 As Byte ' ...
GUID12 As Byte ' ...
GUID13 As Byte ' ...
GUID14 As Byte ' ...
GUID15 As Byte ' ...
DEVDESC As D3DDEVICEDESC ' Device description for use by D3DRM
HDW As Boolean ' Device is hardware
EMU As Boolean ' Device is software-emulated
RGB As Boolean ' Device has rgb caps
MONO As Boolean ' Device has mono ramp caps
End Type
' Viewport window for scrolling effects windows
Public Type tDDWindow
nX As Integer
nY As Integer
nDX As Integer
nDY As Integer
oDDSurface As IDirectDrawSurface3
dRenderArea As RECT
End Type
Global PickInfo As String
' APPERROR: Reports application errors and terminates application properly
Public Sub AppError(nNumber As Long, sText As String, sSource As String)
' Enable error handling
On Error Resume Next
' Cleanup
Call AppTerminate
' Display error
MsgBox "ERROR: " & IIf(InStr(1, UCase(sText), "AUTOM") > 0, "DirectX reports '" & GetDXError(nNumber) & "'", " Application reports '" & sText & "'") & vbCrLf & "SOURCE: " & sSource, vbCritical + vbOKOnly, "XDEMO3D"
' Terminate program
End
End Sub
Public Sub AppInitialize() 'Startup of program
' Enable error handling
On Error GoTo E_AppInitialize
' Setup local variables...
Dim L_dDDSD As DDSURFACEDESC ' Utility surface description
Dim L_dDDSC As DDSCAPS ' Utility display capabilities description
Dim L_oD3DIM As IDirect3D2 ' Utility Direct3DIM interface for retrieving drivers
Dim L_dDDCK As DDCOLORKEY ' Color key for applying to various surfaces
' Initialize DirectDraw interface instance ...
' Create DirectDraw instance
DirectDrawCreate ByVal 0&, G_oDDInstance, Nothing
' Check instance existance, terminate if missing
If G_oDDInstance Is Nothing Then
AppError 0, "Could not create DirectDraw instance", "AppInitialize"
Exit Sub
End If
' Set cooperation mode of DirectX
G_oDDInstance.SetCooperativeLevel fMain.hWnd, DDSCL_EXCLUSIVE Or DDSCL_FULLSCREEN
' Set display mode
G_oDDInstance.SetDisplayMode 640, 480, 16
' Initialize primary surface description
With L_dDDSD
' Get Structure size
.dwSize = Len(L_dDDSD)
' Structure uses Surface Caps and count of BackBuffers
.dwFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
' Structure describes a flippable (buffered) surface
.DDSCAPS.dwCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX Or DDSCAPS_SYSTEMMEMORY
' Structure uses one BackBuffer
.dwBackBufferCount = 1
End With
' Create primary surface from structure
G_oDDInstance.CreateSurface L_dDDSD, G_oDDPrimary, Nothing
' Check primary existance, terminate if missing
If G_oDDPrimary Is Nothing Then
AppError 0, "Could not create primary surface", "AppInitialize"
Exit Sub
End If
' Initialize backbuffer from primary ...
' Set surface description to backbuffer creation
L_dDDSD.dwFlags = DDSD_CAPS
L_dDDSD.DDSCAPS.dwCaps = DDSCAPS_BACKBUFFER
' Create backbuffer from frontbuffer
G_oDDPrimary.GetAttachedSurface L_dDDSD.DDSCAPS, G_oDDBackbuffer
' Check backbuffer existance, terminate if missing
If G_oDDBackbuffer Is Nothing Then
AppError 0, "Could not create backbuffer", "AppInitialize"
Exit Sub
End If
' Initialize windows for displaying various effects
Call CreateWindows
' Initialize Direct3DRM interface instance ...
' Create Direct3DRM instance
Direct3DRMCreate G_oD3DInstance
' Check instance existance, terminate if missing
If G_oD3DInstance Is Nothing Then
AppError 0, "Could not create D3DRM instance", "AppInitialize"
Exit Sub
End If
' Initialize Direct3DRM driver ...
' Get a Direct3D immediate object from the existing DirectDraw object
Set L_oD3DIM = G_oDDInstance
' Set error handler to local for enumeration only
On Error Resume Next
' Start the callback that does the driver enumeration
L_oD3DIM.EnumDevices AddressOf EnumDeviceCallback, 0
' Catch any error resulting from the enumeration and terminate
If err.Number > 0 Then
AppError err.Number, err.Description, "AppInitialize"
Exit Sub
End If